from django.db import models
from django.contrib.auth.models import User
from django.contrib import admin

def_max_length = 255

class Entry(models.Model):

    #volunteers  = models.ManyToManyField(User)
    #address = models.CharField(max_length=def_max_length)
    #address = models.CharField(max_length=def_max_length)
    #number_volunteers_needed = models.IntegerField()	
    #city = models.CharField(max_length=def_max_length)
    #county = models.CharField(max_length=def_max_length)
    #email = models.CharField(max_length=def_max_length)
    #crop_type = models.CharField(max_length = def_max_length)
    #start_time = models.DateTimeField()
    #instructions = models.TextField()
    #users = models.ManyToManyField(User)
    #date = models.DateField(blank=True)
 

    title = models.CharField(max_length=40)
    snippet = models.CharField(max_length=150, blank=True)
    body = models.TextField(max_length=10000, blank=True)
    created = models.DateTimeField(auto_now_add=True)
    date = models.DateField(blank=True)
    creator = models.DateField(blank=True)
    remind = models.BooleanField(default=False)

    def __unicode__(self):
        if self.title:
            return unicode(self.creator) + u" - " + self.title
        else:
            return unicode(self.creator) + u" - " + self.snippet[:40]

    def short(self):
        if self.snippet:
            return u"<i>%s</i> - %s" % (self.title, self.snippet)
        else:
            return self.title
    short.allow_tags = True

    class Meta:
        verbose_name_plural = "entries"


### Admin

class EntryAdmin(admin.ModelAdmin):
    list_display = ["creator", "date", "title", "snippet"]
    search_fields = ["title", "snippet"]
    list_filter = ["creator"]
